package com.example.fragmentest.fragment;

import android.Manifest;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.example.fragmentest.Beam.User;
import com.example.fragmentest.R;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;


public class FinstFragment extends Fragment {
    private ListView lv;
    private List<String>dataList=new ArrayList<>();
    private List<User> userList=new ArrayList<>();
    String[] a={"1","2","3"};

    public FinstFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_finst, container, false);
        initView(view);
        setListener();
        return view;
    }

    private void setListener() {
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                showToast("你点击了"+ dataList.get(position));
            }
        });
    }
    private void showToast(String str){
        Toast.makeText(getContext(),str,Toast.LENGTH_LONG).show();
    }

    private void initView(View view) {
        userList= LitePal.findAll(User.class);
        dataList.clear();
        for (User u:userList){
            dataList.add("id:"+u.getId()+"名字"+u.getName()+"密码："+u.getPsd());
        }
        lv=view.findViewById(R.id.fraglv);
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(getContext(),
                android.R.layout.simple_list_item_1,dataList);
        lv.setAdapter(adapter);
    }


}
